package com.nsjr.jrznandroid;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.widget.FrameLayout;
import android.widget.RadioGroup;
import com.jrzn.base.BaseActivity;

public class MainActivity extends BaseActivity {
    private RadioGroup group;
    private FragmentManager fragmentManager;
    private FragmentTransaction fragmentTransaction;
    private Fragment[] mFragments;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findview();
    }
    private void findview(){
        mFragments = new Fragment[4];
        fragmentManager = getSupportFragmentManager();
        mFragments[0] = fragmentManager.findFragmentById(R.id.fragement_frag1);
        mFragments[1] = fragmentManager.findFragmentById(R.id.fragement_frag2);
        mFragments[2] = fragmentManager.findFragmentById(R.id.fragement_frag3);
        mFragments[3] = fragmentManager.findFragmentById(R.id.fragement_frag4);
        fragmentTransaction = fragmentManager.beginTransaction().hide(mFragments[0]).hide(mFragments[1]).hide(mFragments[2]).hide(mFragments[3]);
        fragmentTransaction.show(mFragments[0]).commit();
         group = (RadioGroup) findViewById(R.id.act_main_radiogroup);
        group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup arg0, int arg1) {
                // TODO Auto-generated method stub
                fragmentTransaction = fragmentManager.beginTransaction()
                        .hide(mFragments[0]).hide(mFragments[1])
                        .hide(mFragments[2]).hide(mFragments[3]);
                switch (arg1) {
                    case R.id.act_main_radiobutton1:
                        fragmentTransaction.show(mFragments[0]).commit();
                        break;
                    case R.id.act_main_radiobutton2:
                        fragmentTransaction.show(mFragments[1]).commit();
                        break;
                    case R.id.act_main_radiobutton3:
                        fragmentTransaction.show(mFragments[2]).commit();
                        break;
                     case R.id.act_main_radiobutton4:
                        fragmentTransaction.show(mFragments[3]).commit();
                         break;
                }
            }
        });
    }
}
